<?php

class SON_Plugins_Placeholders_Eleicoes extends Zend_Controller_Plugin_Abstract
{
    public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
    {
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
        $viewRenderer->initView();
        $view = $viewRenderer->view;

        $eleicao = new Eleicao();
        $eleicoes = $eleicao->getEleicoes();

        $content = '';
        
        if ($eleicoes) {
	        
        	$content = '<li class="dropdown">';
	        $content .= '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Candidatos <b class="caret"></b></a>';
	        $content .= '<ul class="dropdown-menu">';
	        
	        foreach ($eleicoes as $e)
	            $content.= '<li><a href="' . $view->url(array('module' => 'default', 'controller' => 'candidatos', 'eleicao' => $e->getAno()), null, true) .'">' . $e->getAno() . '</a></li>';
	
	        $content.= "</ul>";
	        $content.= "</li>";
        }

        $view->placeholder('eleicoes')->append($content);
    }
}
